package chapter1.dataabstraction.example;

/**
 * @author quanlinlin on 2018/11/17 15:36.
 * @version 1.0
 */
public class Accumulator {

    private double total;

    private int N;

    public void addDataValue(double val) {
        N++;
        total += val;
    }

    /**
     * 返回平均值
     *
     * @return
     */
    public double mean() {
        return total / N;
    }

    @Override
    public String toString() {
        return "Mean (" + N + " values): "
                + String.format("%7.5f", mean());
    }
}
